Deployment And Automation
What inference methods are available, and when should each be used?
- Batch inference: Score many records periodically and write predictions to Delta tables or storage; best for nightly risk scores or recommendations where low latency is unnecessary.
- Streaming inference: Score incoming records as they arrive through streaming pipelines; useful for near-real-time event processing.
- Real-time inference: Send individual requests to a REST endpoint and receive low-latency predictions; ideal for interactive applications. Mosaic AI Model Serving primarily provides this mode.
- Edge inference: Run a model on a local device with intermittent connectivity; this is a deployment pattern, not a standard Mosaic AI Model Serving mode.
- Balance latency, throughput, infrastructure cost, security and freshness when choosing a mode.
How does Mosaic AI Model Serving work?
- Model Serving exposes registered MLflow/Unity Catalog models through managed REST endpoints; supported serving options also include foundation and external models.
- MLflow supplies model artifacts, dependencies and signatures; Model Serving manages endpoint infrastructure, scaling, traffic routing and access.
- Inference tables can capture requests and responses for monitoring, subject to supported endpoint configuration, governance and privacy requirements.
- Use Scale to zero in Free Edition where required to conserve endpoint capacity. The first request after inactivity may be slow because the endpoint must restart; avoid this setting when consistent production latency matters.
- The serving endpoint and its model version are distinct: changing a registered model does not automatically mean a deployed endpoint has switched versions.
How do you deploy a registered ML model to a serving endpoint?
- Prerequisite: complete training and register the model in Unity Catalog, for example
dbacademy.get_started_ml.my_model; confirm its version and input signature. - Open Catalog Explorer → Models, select the registered model and choose Serve this model; alternatively open Serving → Create serving endpoint.
- Enter an endpoint name such as
yourname-model, select the registered model and version, review workload size and scale-out, and enable Scale to zero if appropriate. - Course warning: The earlier training notebook already creates an endpoint. Inspect and reuse it; do not create a duplicate or exceed Free Edition quotas.
- Wait for endpoint status Ready; provisioning can take approximately 10–12 minutes or longer.
- The deployment can also be automated using the Databricks SDK or
mlflow.deployments.get_deploy_client('databricks'); specify served model/entity, version, workload size and traffic routing. Check the installed SDK’s current argument names before running code. - Grant endpoint query permissions only to intended users or service principals, and keep model versions and deployment changes traceable.
How do you test and query a deployed model?
- Open Serving → your endpoint → Use → Browser. The request editor may be populated from the input example logged with MLflow; select Send request and inspect the prediction.
- Use Query endpoint or the REST API/SDK for programmatic testing; the request JSON must match the deployed model’s signature.
- Where the endpoint supports SQL AI Functions, use
ai_query()with its endpoint name and an appropriately shaped request. For the wine example, the course uses:
SELECT ai_query(
'YOUR_ENDPOINT_NAME',
request => named_struct(
'wine_id', 722,
'fixed_acidity', 6.8,
'volatile_acidity', 0.64,
'citric_acid', 0.0,
'pH', 3.44,
'sulphates', 0.63,
'alcohol', 11.3,
'pHCategory', 2.0
),
returnType => 'DOUBLE'
) AS prediction;- Important: The example fields and
DOUBLEreturn type are specific to the course model; your endpoint may require a different input shape or return type. Check the MLflow signature and endpoint schema first. The sample’spHCategoryis also derived frompH; ensure the same feature transformation used during training is applied at inference. - Test multiple known cases, invalid inputs and missing fields; compare predictions with offline model results.
- If a scaled-to-zero endpoint responds slowly on the first request, allow for cold-start latency before diagnosing a failure.
How do Lakeflow components automate machine learning?
- Lakeflow Connect: Ingest data from supported sources into Databricks.
- Lakeflow Declarative Pipelines: Transform and validate raw data into reliable feature-ready Delta tables.
- Lakeflow Jobs: Orchestrate notebook, Python, SQL and pipeline tasks; define dependencies, retries, schedules and notifications.
- Typical workflow: ingest → validate/transform → engineer features → train/evaluate → register → deploy → monitor.
- Prefer deploying versioned, tested code through jobs and CI/CD rather than relying on manual notebook runs; isolate development and production configurations.
- Schedule retraining only when justified by data freshness, drift and business requirements; use evaluation gates before promoting a new model.
How do you create and inspect a Lakeflow Job?
- Navigate to Jobs & Pipelines → Create → Job, then add a Notebook task.
- Enter a task name, choose Workspace as the source and select the notebook path.
- Select compatible job compute or serverless compute according to the workspace and notebook requirements. The course uses an all-purpose cluster, but production jobs commonly use job-specific compute.
- Save the task, name the job (for example,
Workflow1) and select Run now. - Open Jobs & Pipelines → job → Runs → run details to inspect status, task logs, errors and a snapshot of notebook output.
- For production, add a schedule or event trigger, retries, timeout, notifications and dependent tasks; pass parameters rather than hard-coding environment-specific values.
- Caution: A job that reruns a notebook containing model registration or endpoint creation may create unwanted model versions or infrastructure changes. Separate setup, training and deployment steps and make operations idempotent where possible.
What is the Data Science Agent and how can you use it for EDA?
- The Data Science Agent is an agentic Databricks Assistant experience that helps discover data, generate analysis code, build charts and propose ML workflows through natural-language instructions. Availability and UI names vary by workspace.
- Open a notebook, select the Assistant side panel and switch to Agent mode if available. Review any generated code and requested actions before approving execution.
- Example data-discovery prompt:
Find a dataset that contains wine quality data. - Reference a known table precisely using autocomplete, such as
@wine_quality_table, then ask:Show its schema, first rows, missing values and descriptive statistics. - Follow with:
Analyse distributions, correlations, outliers and potential data quality issues; show the SQL or Python used. - Use the generated EDA as a starting point. Verify row counts, missing-value handling, numeric types, leakage risks and whether the sample represents the real business population.
How do you use the Data Science Agent to develop and explain models?
- Ask it to define the prediction target and recommend classification versus regression based on the dataset and business use case.
- Example:
Train baseline and Random Forest models to predict wine quality. Use a held-out test set and cross-validation; report appropriate metrics and compare against a naive baseline. - Ask for hyperparameter tuning with
GridSearchCVorRandomizedSearchCV, performed only on training folds, leaving the test set untouched until final evaluation. - Ask:
Show feature importance and, where suitable, SHAP explanations. Explain the difference between predictive association and causation. - Require reproducible code, random seeds, model signatures and MLflow tracking; inspect training data and transformations before accepting generated results.
- Important course distinction: Earlier notebooks classify
pHCategory(a category derived frompH), while these prompts suggest predicting wine quality. These are different target variables; do not compare their metrics as though they were the same experiment. - Have the agent summarise business implications, uncertainties, limitations and next steps, but independently verify every consequential conclusion.
How do you monitor and troubleshoot automated serving?
- Track endpoint availability, error rates, latency, throughput, costs and inference request/response distributions.
- Use inference tables and monitoring tools where supported to investigate feature drift and prediction drift; calculate actual model quality only when ground-truth labels become available.
- Endpoint not ready: Check provisioning status, model dependencies, serving logs and Free Edition quotas.
- Invalid request: Compare JSON field names, types, null handling and array/object structure against the logged model signature.
- Job fails: Open the specific failed task’s run output, confirm permissions, compute compatibility, library versions and referenced catalog/schema/table names.
- Predictions differ from training: Check feature transformations, feature lookup logic, missing-value treatment and model version; avoid training-serving skew.
- Use least-privilege service principals for scheduled workflows, and protect sensitive inference inputs and outputs.